local StringUtil = require("util.StringUtil")
local startTime = os.time();
require("util.PrintUtil")
local log = require("core.log")



--[[
spring.redis.cluster.nodes=192.168.213.169:6369,192.168.213.171:6369,192.168.213.172:6369
spring.redis.passwor=stA8E2q7Bduv5MIZ
spring.redis.index=0
]]--
--- 从配置中获取redis 集群地址
---
local redis_nodes = ngx.shared.properties:get("spring.redis.cluster.nodes");
local redis_pwd = ngx.shared.properties:get("spring.redis.password");
local redis_index = ngx.shared.properties:get("spring.redis.index");


---分割根据逗号 在根据冒号
if not redis_nodes then
    log.error("not found  redis config from consul" )
    return;

end

if not redis_pwd then
    log.error("not found  redis pwd" )
    return;

end
local redis_temp_ary =StringUtil.split(redis_nodes,",")
local serv_list = {};


for k, v in ipairs(redis_temp_ary) do
    print("打印找到的consul中的redis 配置")
    print(k, v)
    print("consul中的redis 配置 index:"..k.." value: "..v)
    local ip_port = StringUtil.split(v,":")
    print("打印找到的consul中的redis 配置")
    serv_list[#serv_list+1]={ip=ip_port[1],port=tonumber(ip_port[2])};
    print("ip:"..ip_port[1].." port: "..ip_port[2])
end




printTable(serv_list,1);
serv_list.name="test";
local config = {
    name = "test1",

    --
    serv_list =serv_list,
    password=redis_pwd,
}
--config["serv_list"] = serv_list;
local redis_cluster = require "resty.rediscluster";

local red = redis_cluster:new(config)
if not red then
    print("redis 链接失败")
    return;
end
red:auth(redis_pwd)



------测试代码----------

red:set("1","2");
red:get("1");
